<template>
  <el-dialog
    :close-on-click-modal="false"
    title="计划接收"
    v-model="visible"
    align-center
    width="600px"
    destroy-on-close
  >
    <el-form ref="formRef" :model="form" label-position="top">
      <el-radio-group v-model="form.audit_result">
        <el-radio :value="1">接收</el-radio>
        <el-radio :value="2">驳回</el-radio> </el-radio-group
      ><br />
      <template v-if="form.audit_result == 2">
        <el-form-item
          label="驳回原因"
          prop="plan_reject_reason"
          :rules="[{ required: true, message: '不能为空', trigger: 'change' }]"
        >
          <VSelect
            v-model="form.plan_reject_reason"
            placeholder="请选择"
            :options="options"
            class="w-full"
          />
        </el-form-item>
      </template>
    </el-form>
    <template #footer>
      <el-button @click="handleClose(false)">取 消</el-button>
      <el-button type="primary" :loading="loading" @click="save"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>
<script setup>
import { ElMessage } from "element-plus";
import { purchaseDemandBatchReceive } from "../../api";
import { resMessage } from "@/utils/res";
const props = defineProps({
  options: { type: Array, default: () => [] },
});
const emit = defineEmits(["close", "success"]);
const loading = ref(false);
const visible = ref(false);
const form = ref({ audit_result: 1 });
// 打开弹窗
const open = async (id) => {
  visible.value = true;
  form.value.dd_ids = id;
};
const save = async () => {
  try {
    loading.value = true;
    const res = await purchaseDemandBatchReceive(form.value);
    resMessage({
      res,
      success: () => {
        ElMessage.success("操作成功");
        handleClose(true);
      },
    });
  } finally {
    loading.value = false;
  }
};
const handleClose = (refresh) => {
  visible.value = false;
  form.value = { audit_result: 1 };
  emit("close");
  refresh && emit("success");
};
defineExpose({ open });
</script>
